<!DOCTYPE html>
<html>

	<head lang="en">
		<title>找攻略</title>
		<meta charset="utf-8" />
		<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
		<link rel="stylesheet" href="/js/bootstrap-4.1.1-dist/css/bootstrap.min.css">
		<script src="/js/jquery/jquery.min.js"></script>
		<script src="/js/bootstrap-4.1.1-dist/js/bootstrap.min.js"></script>
		<link rel="stylesheet" href="/css/font/css/font-awesome.min.css" />
		<link rel="stylesheet" href="/css/reset.css" />
		<link rel="stylesheet" href="/css/strategy.css" />
		<script src="/js/plugins/jrender/jrender.min.js"></script>
		<link rel="stylesheet" href="/js/plugins/dialog2/dialog.css">
		<script src="/js/plugins/dialog2/dialog.min.js"></script>
		<script>
			$(function () {

                //去游记推荐中获取一篇游记推荐中类型为攻略推荐的文章
                $.get("/travelCommends",{type:3,pageSize:1},function (data) {
                    //data此时是一个pageInfo,直接拿里面的第0个list进行渲染
                    //渲染数据
                    $(".commend").renderValues(data.list[0],{
                        getHref:function (item,value) {
                            //item就是要渲染数据的标签,那个贴了很多属性的a标签
                            $(item).attr("href",$(item).data("href")+value);//动态地呈现编辑的信息,拼接上每个文章的id
                        }
                    });
                });

                //获取状态为推荐的所有大攻略,设置页面大小为0,查出所有满足条件的数据
				$.get("/strategies",{state:1,pageSize:0},function (data) {
                    $(".strategyCommend").renderValues(data,{
                        getHref:function (item,value) {
                            $(item).attr("href",$(item).data("href")+value);
                        }
					});
                });//用来显示推荐页的所有当季推荐

                //当前浏览的地区id
                var regionId;

				//获取推荐的地区(我们原来有一个获取所有地区的接口,现在往里面多设计一个参数)
				$.get("/regions",{state:1},function (data) {
                    var temp="";
                    var content="";
                    $.each(data,function (index,ele) {
                        //拼页面上的条栏.自定义属性rid==>地区的id,跳转带上地区的id,
                        temp += '<li class="nav-item"><a data-rid="'+ele.id+'" class="nav-link" data-toggle="pill" href="#pills-'+ele.id+'">'+ele.name+'</a></li>';
                        //拼每个地区条目里的内容
                        content += '<div class="tab-pane fade"  id="pills-'+ele.id+'">'+index+'</div>';
                    })
					//拼接标题
					$("#pills-tab").append(temp);
					//拼接内容,在推荐那栏往后
                    $("#pills-tabContent").append(content);
                    //等上面拼完了,(给页面上的条栏)绑定点击事件

					$(".nav-link").click(function () {
                        var rid =$(this).data("rid");
                        regionId=rid;//赋值给成员变量
						//重置当前页和总页数
						currentPage=2;
						pages=2;
                        //如果有地区id,才获取数据
                        if(rid) {
                            //获取html数据
                            $.get("/regions/"+rid+"/strategies",function (data) {
                                //data是拼好真实数据的模板内容,我们将它拼进内容栏里面
								$("#pills-"+rid).html(data);
                            },"html");
                        }
                    });
                });
				//当前页,初始值为2
                var currentPage=2;
                //总页数
                var pages=2;

                //发送ajax请求
                function query() {
                    if(regionId){
                        $.get("/regions/"+regionId+"/strategies",{currentPage:currentPage},function (data) {//data是返回的pageInfo
                            //不用数组,用拼接大法
                            var temp="";
                            $.each(data.list,function (index,ele) {
                                temp += ' <div class="col-6 mb">\n' +
                                    '                <a href="../strategyCatalogs.html?id=' + ele.id + '">\n' +
                                    '                    <img class="float-left " src="' + ele.coverUrl + '">\n' +
                                    '                    <div class="classify-text">\n' +
                                    '                        <span >' + ele.title + '</span>\n' +
                                    '                        <p>0人收藏</p>\n' +
                                    '                    </div>\n' +
                                    '                </a>\n' +
                                    '            </div>';
								
                            });
                            $(".classify").append(temp);//拼接到全部攻略下面
                            pages=data.pages;//给总页数赋值
                        },"json");
                        //当前页加一
                        currentPage++;
                    }
                }
                //监听鼠标滚动事件
                $(window).scroll(function () {
                    //当文档滚上去的高度+窗口的高度>=html整个文档的高度,
                    if($(document).scrollTop()+$(window).height()>=$(document).height()-1){
                        //并且当前页小于等于总页数时,执行分页查询
                        if(currentPage<=pages){
                            query();
                        }else{
                            $(document).dialog({
                                type:'notice',
                                content:'<span class="info-text">已经到底了!</span>',
                                autoClose:1500
                            });
                        }
                    }
                });
            });
		</script>
	</head>
	<body>
	<div class="search-head">
		<div class="row nav-search">
			<div class="col-2">
				<a href="index.html">
					<span><i class="fa fa-chevron-left fa-2x"></i></span>
				</a>
			</div>
			<div class="col-10">
				<div class="input-group-sm search">
					<input class="form-control searchBtn" placeholder="找攻略">
				</div>
			</div>
		</div>
	</div>
	<ul class="nav nav-pills nav-justified border border-left-0 border-top-0 border-right-0" id="pills-tab" role="tablist">
		<li class="nav-item">
			<a class="nav-link active show" id="pills-top-tab" data-toggle="pill" href="#pills-top">
				<span style="font-weight: bold;">推荐</span>
			</a>
		</li>
	</ul>

	<div class="tab-content" id="pills-tabContent">
		<div class="tab-pane fade active show" id="pills-top">
			<div class="container commend">
				<a  data-href="travelContent.html?id=" render-key="travel_id" render-fun="getHref">
					<img  render-src="coverUrl">
					<p render-html="title"></p>
				</a>
			</div>
			<hr>
			<div class="container strategyCommend">
				<h6>当季推荐</h6>
				<div class="row hot" render-loop="list">
					<div class="col-4">
					<a data-href="strategyCatalogs.html?id=" render-key="list.id" render-fun="getHref" >
						<img  render-src="list.coverUrl">
						<p render-html="list.title"></p>
					</a>
				   </div>
				</div>
			</div>
		</div>
		<!--拼接内容的模板-->
		<!--<div class="tab-pane fade" id="pills-1"></div>-->

	</div>
	</body>

</html>